package org.example.pack1210.dao;

import lombok.SneakyThrows;
import org.example.pack1210.bean.Dept;
import org.example.pack1210.db.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Dept2DAO {
    private Connection conn;
    private PreparedStatement ps;
    private ResultSet rs;

    @SneakyThrows
    public Dept findById(int id) {
        Dept dept = new Dept();
        conn = DBManager.getConnection2();
        String sq1 = "select*form dept where deptno=?";
        ps = conn.prepareStatement(sq1);
        ps.setInt(1, id);
        rs = ps.executeQuery();
        if (rs.next()) {
            dept.setDeptNo(id);
            dept.setDname(rs.getString(2));
            dept.setLoc(rs.getString(3));
            return dept;
        }
        return null;
    }
}
